{% extends 'base.html' %}
{% block title %}
    内容管理
{% endblock %}
{% block scrtpt %}
    {{ super() }}
    <script>
        $(document).ready(function () {
            $(".center-div").hide();
            $("#myArticle").show();
        });

        function showDiv(id) {
            $(".center-div").hide();
            $(id).show();
        }
    </script>
{% endblock %}
{% block content %}
    <div id="button-div" class="col-md-5 col-md-offset-3">
        <div class="col-md-5 col-md-offset-2"><input type="button" class="btn btn-info" value="我的文章"
                                                     onclick="showDiv('#myArticle')"></div>
        <div class="col-md-2"><input type="button" class="btn btn-info" value="我的收藏"
                                     onclick="showDiv('#myFav')"></div>
    </div>
    <div id="myArticle" class="col-md-5 col-md-offset-3 center-div">
        {% if articles %}
            <table class="table table-bordered">
                <tr>
                    <th>序号</th>
                    <th>我的文章</th>
                    <th>操作</th>
                </tr>
                {% for article in articles %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td>
                            <a href="{{ url_for('article.articleDetail') }}?articleId={{ article[0] }}">{{ article[2] }}</a>
                        </td>
                        <td><a href="{{ url_for('user.deleteArticle') }}?articleId={{ article[0] }}"><input
                                type="button"
                                class="btn btn-danger btn-sm"
                                value="删除"></a>
                        </td>
                    </tr>
                {% endfor %}
            </table>
        {% else %}
            <h1>你还没有发表过文章哦~</h1>
        {% endif %}

    </div>
    <div id="myFav" class="col-md-5 col-md-offset-3 center-div">
        {% if favs %}
            <table class="table table-bordered">
                <tr>
                    <th>序号</th>
                    <th>我的收藏</th>
                    <th>操作</th>
                </tr>
                {% for fav in favs %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td><a href="{{ url_for('article.articleDetail') }}?articleId={{ fav[1] }}">{{ fav[3] }}</a>
                        </td>
                        <td><a href="{{ url_for('user.deleteFav') }}?favId={{ fav[0] }}"><input type="button"
                                                                                                class="btn btn-danger btn-sm"
                                                                                                value="删除"></a></td>
                    </tr>
                {% endfor %}
            </table>
        {% else %}
            <h1>你还没有收藏文章哦~</h1>
        {% endif %}

    </div>
{% endblock %}